/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Control;

/**
 *
 * @author Juan Ortiz
 */
public class SMAForecasting implements IForecasting{

    @Override
    public Double[] forecast(Double[] inputs) throws IllegalArgumentException{
        
        if(!Validator.validate(inputs))
            throw new IllegalArgumentException("The inputs' number must be equal or greater than 5.");
        
        Double[] outputs = new Double[inputs.length];
        outputs[0] = (inputs[0] + inputs[1])/2;
        for(int i=1; i < inputs.length - 1; i++) {
            outputs[i] = outputs[i-1] - (inputs[i - 1]/inputs.length) + (inputs[i + 1]/inputs.length);
        }
        outputs[inputs.length - 1] = (outputs[0] + outputs[inputs.length - 2])/2;
        return outputs;
    }
    
}
